using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using TShockAPI;
using TShockAPI.DB;

namespace Search.DB
{
    /// <summary>
    /// wiki表
    /// wiki语言包中修正中文物品部分
    /// </summary>
    public class DBWiki
    {
        private IDbConnection database;

        /// <summary>
        /// wiki表
        /// </summary>
        /// <param name="db"></param>        
        /// <param name="exist">db文件是否存在，如果不存在则生成已知物品名称到初始数据库中</param>
        public DBWiki(IDbConnection db, bool exist)
        {
            database = db;

            SqlTableCreator sqlcreator = new(db, db.GetSqlType() == SqlType.Sqlite ? new SqliteQueryCreator() : new MysqlQueryCreator());
            sqlcreator.EnsureTableStructure(
                new SqlTable("Wiki",
                    new SqlColumn("ID", MySqlDbType.Int32) { Primary = true, Unique = true },
                    new SqlColumn("Name", MySqlDbType.VarChar)
            ));

            if (!exist)
                Initialize();
        }


        /// <summary>
        /// 将wiki和游戏内有差异的物品名写入数据表中
        /// </summary>
        void Initialize()
        {
            #region wiki语言包
            // Wiki语言包
            // （更新日志：2022 年 11 月 29 日 上午 12:00）
            Dictionary<int, string> dict = new() {
                { 1113, "粉仙人掌果"},
                { 113, "魔法飞弹"},
                { 1134, "瓶装蜂蜜"},
                { 1259, "花之力"},
                { 126, "瓶装水"},
                { 1305, "吉他斧"},
                { 1340, "毒液药剂"},
                { 1353, "诅咒焰药剂"},
                { 1354, "烈火药剂"},
                { 1355, "金药剂"},
                { 1356, "灵液药剂"},
                { 1357, "纳米机器人药剂"},
                { 1358, "派对药剂"},
                { 1359, "毒药剂"},
                { 1373, "上吊的人"},
                { 1425, "哥布林打扑克牌"},
                { 1428, "泰拉哥特式"},
                { 1436, "眼睛的永恒"},
                { 1437, "独角兽穿越神圣之地"},
                { 1438, "浪里"},
                { 1443, "护士丽莎"},
                { 1453, "锈蚀连队旗"},
                { 1454, "褴褛兄弟会旗"},
                { 1456, "恶魔纹章旗"},
                { 147, "尖刺"},
                { 1491, "沙的秘密"},
                { 1495, "美国爆炸式"},
                { 1500, "直面幕后大脑"},
                { 155, "村正"},
                { 1576, "罕见魔法"},
                { 1597, "八音盒（太空夜晚）"},
                { 1599, "八音盒（Boss 4）"},
                { 1600, "八音盒（地表世界备选曲）"},
                { 1604, "八音盒（海洋白天）"},
                { 1607, "八音盒（Boss 5）"},
                { 1672, "蘑菇瓢虫旗"},
                { 1715, "吧台"},
                { 1739, "巫师之帽"},
                { 177, "蓝玉"},
                { 178, "红玉"},
                { 1787, "南瓜派"},
                { 1895, "五彩串灯"},
                { 1896, "红串灯"},
                { 1897, "绿串灯"},
                { 1898, "蓝串灯"},
                { 1899, "黄串灯"},
                { 1900, "红黄串灯"},
                { 1901, "红绿串灯"},
                { 1902, "黄绿串灯"},
                { 1903, "蓝绿串灯"},
                { 1904, "红蓝串灯"},
                { 1905, "蓝黄串灯"},
                { 1908, "冬青树"},
                { 1910, "精灵熔枪"},
                { 1989, "女性人体模型"},
                { 216, "镣铐"},
                { 2173, "铜护板"},
                { 2208, "泰拉饲养笼"},
                { 2214, "砌砖刀"},
                { 2432, "铜护板墙"},
                { 2452, "猫鱼"},
                { 2458, "坠落星鱼"},
                { 2460, "骷髅王鱼"},
                { 2462, "饿鬼鱼"},
                { 2465, "幻象鱼"},
                { 2466, "突变雪怪鱼"},
                { 274, "暗黑长枪"},
                { 285, "鞋带束头"},
                { 2904, "骷髅李旗"},
                { 2949, "火星灰咕噜旗"},
                { 464, "鸟雕像"},
                { 537, "钴薙刀"},
                { 562, "八音盒（地表世界）"},
                { 564, "八音盒（夜间）"},
                { 567, "八音盒（Boss 1）"},
                { 572, "八音盒（Boss 2）"},
                { 574, "八音盒（Boss 3）"},
                { 676, "寒霜剑"},
                { 751, "云"},
                { 758, "榴弹发射器"},
                { 849, "致动器"},
                { 3620, "致动魔杖"},
                { 3763, "0x33的飞行员风镜"},
                { 3250, "绿马掌气球"},
                { 3252, "粉马掌气球"},
                { 3060, "骨头拨浪鼓"},
                { 2771, "扰脑器"},
                { 2876, "淡棕染料"},
                { 3110, "天界贝壳"},
                { 2882, "充能爆破炮"},
                { 3299, "青绳"},
                { 3396, "苍蝇人博士旗"},
                { 3659, "鸭雕像"},
                { 3349, "异域弯刀"},
                { 3693, "机关蓝地牢箱"},
                { 3694, "机关骨箱"},
                { 3689, "机关针叶木箱"},
                { 3695, "机关仙人掌箱"},
                { 3665, "机关宝箱"},
                { 3680, "机关腐化箱"},
                { 3681, "机关猩红箱"},
                { 3684, "机关王朝箱"},
                { 3668, "机关乌木箱"},
                { 3696, "机关血肉箱"},
                { 3683, "机关冰雪箱"},
                { 3700, "机关玻璃箱"},
                { 3666, "机关金箱"},
                { 3703, "机关花岗岩箱"},
                { 3691, "机关绿地牢箱"},
                { 3682, "机关神圣箱"},
                { 3685, "机关蜂蜜箱"},
                { 3672, "机关冰冻箱"},
                { 3671, "机关常春藤箱"},
                { 3679, "机关丛林箱"},
                { 3677, "机关丛林蜥蜴箱"},
                { 3673, "机关生命木箱"},
                { 3704, "机关大理石箱"},
                { 3701, "机关火星箱"},
                { 3702, "机关陨石箱"},
                { 3688, "机关蘑菇箱"},
                { 3697, "机关黑曜石箱"},
                { 3687, "机关棕榈木箱"},
                { 3670, "机关珍珠木箱"},
                { 3692, "机关粉地牢箱"},
                { 3698, "机关南瓜箱"},
                { 3669, "机关红木箱"},
                { 3675, "机关暗影木箱"},
                { 3667, "机关暗影箱"},
                { 3674, "机关天域箱"},
                { 3690, "机关史莱姆箱"},
                { 3699, "机关阴森箱"},
                { 3686, "机关蒸汽朋克箱"},
                { 3678, "机关水中箱"},
                { 3676, "机关蛛丝箱"},
                { 3222, "火焰花种植盆"},
                { 3016, "血肉指虎"},
                { 3380, "坚固化石"},
                { 3722, "热喷泉"},
                { 3188, "角斗士胸甲"},
                { 3187, "角斗士头盔"},
                { 3189, "角斗士护腿"},
                { 3390, "哥布林术士旗"},
                { 3408, "花岗岩巨人旗"},
                { 2491, "硬鞍"},
                { 3296, "橙绿绳"},
                { 3182, "魔法水滴管"},
                { 2860, "火星管道护板"},
                { 2803, "火星装面具"},
                { 2805, "火星装裤"},
                { 2804, "火星装衣"},
                { 3353, "机械矿车"},
                { 3812, "武僧腰带"},
                { 3806, "武僧浓眉秃头帽"},
                { 3808, "武僧裤"},
                { 3807, "武僧衣"},
                { 3216, "月光草种植盆"},
                { 3370, "八音盒（天界柱）"},
                { 3527, "星云染料"},
                { 3432, "预言怪旗"},
                { 3055, "橡实"},
                { 3056, "寒流"},
                { 3057, "被诅咒的圣诞骷髅王"},
                { 3757, "Pedguin的兜帽"},
                { 3759, "Pedguin的裤子"},
                { 3758, "Pedguin的夹克"},
                { 3042, "相位染料"},
                { 3106, "变态人的刀"},
                { 3419, "沙贼旗"},
                { 3754, "落沙块"},
                { 3752, "落沙墙"},
                { 3792, "水晶沙鲨旗"},
                { 2794, "蘑菇矿护板"},
                { 2791, "蘑菇矿护板墙"},
                { 2786, "耀斑镐"},
                { 3422, "流体入侵怪旗"},
                { 3425, "星细胞旗"},
                { 3424, "迷你星细胞旗"},
                { 3032, "超级吸收绵"},
                { 3202, "训练假人"},
                { 3243, "税收官衣服"},
                { 3298, "青绿绳"},
                { 2692, "锡护板"},
                { 2691, "锡护板墙"},
                { 3303, "蓝紫绳"},
                { 3530, "虚空染料"},
                { 3220, "幌菊种植盆"},
                { 3632, "青色测重压力板"},
                { 3630, "橙色测重压力板"},
                { 3626, "粉色测重压力板"},
                { 3631, "紫色测重压力板"},
                { 3611, "宏伟蓝图"},
                { 3822, "埃特尼亚魔力"},
                { 3823, "地狱之剑"},
                { 3828, "永恒水晶"},
                { 3837, "埃特尼亚哥布林投弹手旗"},
                { 3838, "埃特尼亚哥布林旗"},
                { 3844, "埃特尼亚飞龙旗"},
                { 3845, "埃特尼亚标枪投掷怪旗"},
                { 3846, "埃特尼亚荧光虫旗"},
                { 3816, "永恒水晶座"},
                { 3884, "水晶箱"},
                { 3885, "金宝箱"},
                { 3886, "机关水晶箱"},
                { 3887, "机关金宝箱"},
                { 3889, "水晶椅"},
                { 3904, "金平台"},
                { 3910, "金工作台"},
                { 3950, "机关蜘蛛箱"},
                { 3955, "病变块"},
                { 3956, "病变块墙"},
                { 3957, "病变平台"},
                { 3958, "病变浴缸"},
                { 3959, "病变床"},
                { 3960, "病变书架"},
                { 3961, "病变烛台"},
                { 3962, "病变蜡烛"},
                { 3963, "病变椅"},
                { 3964, "病变吊灯"},
                { 3965, "病变宝箱"},
                { 3966, "病变时钟"},
                { 3967, "病变门"},
                { 3968, "病变梳妆台"},
                { 3969, "病变灯"},
                { 3970, "病变灯笼"},
                { 3971, "病变钢琴"},
                { 3972, "病变水槽"},
                { 3973, "病变沙发"},
                { 3974, "病变桌"},
                { 3975, "病变工作台"},
                { 3976, "机关病变箱"},
                { 3991, "奥术花"},
                { 3996, "青蛙蹼"},
                { 4013, "烧烤肋排"},
                { 4018, "奶油苏打水"},
                { 4022, "金美味"},
                { 4060, "超级星星炮"},
                { 4071, "涡螺壳"},
                { 4072, "香螺壳"},
                { 4073, "旋螺壳"},
                { 4077, "八音盒（海洋夜晚）"},
                { 4079, "八音盒（太空白天）"},
                { 4080, "八音盒（城镇白天）"},
                { 4081, "八音盒（城镇夜晚）"},
                { 4082, "八音盒（大风天）"},
                { 4091, "反传送门块"},
                { 4126, "病变马桶"},
                { 4137, "乡村俱乐部长裤"},
                { 4138, "乡村俱乐部帽舌"},
                { 4142, "腐变室"},
                { 4164, "机关日耀箱"},
                { 4185, "机关星旋箱"},
                { 4206, "机关星云箱"},
                { 4227, "机关星尘箱"},
                { 4237, "八音盒（白天混音）"},
                { 4265, "高尔夫箱"},
                { 4266, "机关高尔夫箱"},
                { 4267, "沙岩箱"},
                { 4268, "机关沙岩箱"},
                { 4272, "滴滴怪致残者"},
                { 4317, "血锤斧"},
                { 4318, "虚空天塔柱"},
                { 4319, "箭头标牌"},
                { 4320, "彩色箭头标牌"},
                { 4276, "巴斯特雕像"},
                { 4346, "负重石"},
                { 4424, "铁艺栅栏"},
                { 4443, "恶魔地狱矿车"},
                { 4445, "初级集束火箭"},
                { 4447, "湿火箭"},
                { 4457, "初级迷你核弹"},
                { 4433, "盆栽森林树"},
                { 4469, "彩虹猫矿车"},
                { 4470, "派对矿车"},
                { 4471, "荷兰人矿车"},
                { 4541, "僵尸新娘旗"},
                { 4512, "崎岖石墙"},
                { 4513, "腐化赘生墙"},
                { 4514, "腐化团块墙"},
                { 4518, "猩红疮痂墙"},
                { 4519, "猩红尖牙墙"},
                { 4522, "剥落土墙"},
                { 4524, "皱曲土墙"},
                { 4525, "神圣棱柱墙"},
                { 4527, "神圣碎块墙"},
                { 4528, "神圣结晶墙"},
                { 4534, "灰渣墙"},
                { 4537, "破旧石墙"},
                { 4599, "高尔夫铜奖杯"},
                { 4600, "高尔夫银奖杯"},
                { 4601, "高尔夫金奖杯"},
                { 4587, "破旧高尔夫球杆（铁杆）"},
                { 4588, "破旧高尔夫球杆（推杆）"},
                { 4589, "破旧高尔夫球杆（挖起杆）"},
                { 4590, "破旧高尔夫球杆（木杆）"},
                { 4606, "八音盒（丛林夜晚）"},
                { 4603, "小鸟拨浪鼓"},
                { 4574, "竹箱"},
                { 4585, "机关竹箱"},
                { 4628, "燃烧幽魂"},
                { 4630, "史莱姆之沙"},
                { 4632, "沙上的生活"},
                { 4634, "史前留存"},
                { 4636, "乌鲁鲁巨岩"},
                { 4639, "神眼"},
                { 4552, "造雾机"},
                { 4658, "起伏的果岭"},
                { 4659, "静物球习作"},
                { 4660, "球来了！"},
                { 4661, "映像的二重性"},
                { 4668, "夜明涂料"},
                { 4695, "光明之魂瓶"},
                { 4696, "暗影之魂瓶"},
                { 4697, "飞翔之魂瓶"},
                { 4698, "视域之魂瓶"},
                { 4699, "力量之魂瓶"},
                { 4700, "恐惧之魂瓶"},
                { 4682, "放飞鸽子"},
                { 4702, "放飞灯笼"},
                { 4713, "机关沙漠箱"},
                { 4716, "贝壳哨"},
                { 4723, "永不复焉"},
                { 4729, "静物"},
                { 4730, "Ghostar的无极翼"},
                { 4732, "Ghostar的魂罐"},
                { 4733, "Ghostar的上衣"},
                { 4734, "Ghostar的紧身裤"},
                { 4737, "华丽暗影钥匙"},
                { 4738, "苍蝇人博士面具"},
                { 4739, "苍蝇人博士实验服"},
                { 4743, "橄榄球"},
                { 4746, "Safeman的毛毯斗篷"},
                { 4747, "Safeman的晴天"},
                { 4748, "Safeman的太阳裙"},
                { 4749, "Safeman的粉色护腿"},
                { 4754, "Grox The Great的翅膀"},
                { 4755, "Grox The Great的有角风帽"},
                { 4756, "Grox The Great的护胸"},
                { 4757, "Grox The Great的护胫"},
                { 4779, "蘑菇帽"},
                { 4785, "蒙尘牛皮鞍"},
                { 4786, "皇家鎏金鞍"},
                { 4787, "黑铆钉鞍"},
                { 4788, "骑枪"},
                { 4789, "暗影骑枪"},
                { 4790, "神圣骑枪"},
                { 4824, "湿炸弹"},
                { 4847, "熔岩萤火虫"},
                { 4848, "熔岩萤火虫瓶"},
                { 4872, "熔岩吸收绵"},
                { 4866, "吊挂火焰花"},
                { 4882, "紫晶兔兔笼"},
                { 4883, "黄玉兔兔笼"},
                { 4884, "蓝玉兔兔笼"},
                { 4885, "翡翠兔兔笼"},
                { 4886, "红玉兔兔笼"},
                { 4887, "钻石兔兔笼"},
                { 4888, "琥珀兔兔笼"},
                { 4874, "狱炎战靴"},
                { 4797, "皇家美味"},
                { 4798, "可疑咧嘴眼球"},
                { 4808, "海猪肉"},
                { 4812, "南瓜香薰蜡烛"},
                { 4823, "女皇之翼"},
                { 4960, "王室美食"},
                { 4963, "松露虫笼"},
                { 4981, "明胶女式鞍"},
                { 4989, "翱翔徽章"},
                { 4993, "Chippy的沙发"},
                { 5004, "Badger的帽子"},
                { 5009, "一杯茶"},
                { 5015, "异界八音盒（地表世界）"},
                { 5016, "异界八音盒（夜晚）"},
                { 5024, "异界八音盒（雪原）"},
                { 5032, "异界八音盒（Boss 2）"},
                { 5033, "异界八音盒（Boss 1）"},
                { 5035, "异界八音盒（天界柱）"},
                { 5043, "火把神的恩宠"},
                { 5048, "浪人阵笠"},
                { 5075, "彩虹光标"},
                { 5077, "水晶鞋"},
                { 5079, "王子裤"},
                { 5081, "盆栽水晶蕨"},
                { 5082, "盆栽水晶螺旋"},
                { 5083, "盆栽水晶泪滴"},
                { 5084, "盆栽水晶树"},
                { 5085, "公主64"},
                { 5086, "少女画像"},
                { 5087, "神圣之地的黑暗面"},
                { 5090, "独眼巨鹿眼球"},
                { 5099, "花环"},
                { 5108, "独眼巨鹿纪念章"},
                { 5109, "独眼巨鹿面具"},
                { 5111, "宝藏袋（独眼巨鹿）"},
                { 5110, "独眼巨鹿圣物"},
                { 5112, "八音盒（独眼巨鹿）"},
                { 5116, "纵火者裙"},
                { 5113, "收音机"},
                { 5120, "鹿华"},
                { 5123, "丧亲者"},
                { 5148, "珊瑚礁浴缸"},
                { 5149, "珊瑚礁床"},
                { 5150, "珊瑚礁书架"},
                { 5151, "珊瑚礁梳妆台"},
                { 5152, "珊瑚礁烛台"},
                { 5153, "珊瑚礁蜡烛"},
                { 5154, "珊瑚礁椅"},
                { 5155, "珊瑚礁吊灯"},
                { 5156, "珊瑚礁箱"},
                { 5157, "珊瑚礁时钟"},
                { 5158, "珊瑚礁门"},
                { 5159, "珊瑚礁灯"},
                { 5160, "珊瑚礁灯笼"},
                { 5161, "珊瑚礁钢琴"},
                { 5162, "珊瑚礁平台"},
                { 5163, "珊瑚礁水槽"},
                { 5164, "珊瑚礁沙发"},
                { 5165, "珊瑚礁桌"},
                { 5166, "珊瑚礁工作台"},
                { 5167, "机关珊瑚礁箱"},
                { 5168, "珊瑚礁马桶"},
                { 5177, "气球箱"},
                { 5178, "气球时钟"},
                { 5188, "机关气球箱"},
                { 5190, "灰烬木浴缸"},
                { 5191, "灰烬木床"},
                { 5192, "灰烬木书架"},
                { 5193, "灰烬木梳妆台"},
                { 5194, "灰烬木烛台"},
                { 5195, "灰烬木蜡烛"},
                { 5196, "灰烬木椅"},
                { 5197, "灰烬木吊灯"},
                { 5198, "灰烬木箱"},
                { 5199, "灰烬木时钟"},
                { 5200, "灰烬木门"},
                { 5201, "灰烬木灯"},
                { 5202, "灰烬木灯笼"},
                { 5203, "灰烬木钢琴"},
                { 5204, "灰烬木平台"},
                { 5205, "灰烬木水槽"},
                { 5206, "灰烬木沙发"},
                { 5207, "灰烬木桌"},
                { 5208, "灰烬木工作台"},
                { 5209, "机关灰烬木箱"},
                { 5210, "灰烬木马桶"},
                { 5214, "灰烬草种子"},
                { 5215, "灰烬木"},
                { 5216, "灰烬木墙"},
                { 5217, "灰烬木栅栏"},
                { 5218, "被驱逐之人"},
                { 5225, "Kargoh的召唤"},
                { 5227, "给泰拉瑞亚人的机器"},
                { 5228, "泰拉刃纪事"},
                { 5229, "本尼·沃霍尔"},
                { 5232, "二元性"},
                { 5233, "秒差距伙伴"},
                { 5241, "不要吃魔菇！"},
                { 5242, "蓝虎尤玛"},
                { 5243, "月亮人公司"},
                { 5244, "Israpony的阳光"},
                { 5247, "奇异植株"},
                { 5249, "奇异死者"},
                { 5251, "雷电"},
                { 5255, "爱在垃圾桶里"},
                { 5252, "甲壳摄影"},
                { 5263, "沙发笑话"},
                { 5129, "臭虫剑"},
                { 5274, "湖中女士"},
                { 5275, "Joja可乐"},
                { 5276, "星之果实"},
                { 5279, "灰烬木头盔"},
                { 5280, "灰烬木胸甲"},
                { 5281, "灰烬木护胫"},
                { 5282, "灰烬木弓"},
                { 5283, "灰烬木锤"},
                { 5284, "灰烬木剑"},
                { 5285, "月亮球"},
                { 5211, "生物群落视觉药水"},
                { 5136, "瓦尔克精灵耳朵"},
                { 5290, "Jim的帽子"},
                { 5212, "绯红金刚鹦鹉"},
                { 5213, "绯红金刚鹦鹉笼"},
                { 5300, "蓝金刚鹦鹉"},
                { 5301, "蓝金刚鹦鹉笼"},
                { 5291, "回声墙"},
                { 5303, "蜂蜜吸收绵"},
                { 5304, "超强吸收绵"},
                { 5296, "叶绿提炼机"},
                { 5297, "蓝鸡蛋"},
                { 5306, "珊瑚礁块"},
                { 5307, "珊瑚礁墙"},
                { 5130, "Lilith的项链"},
                { 5311, "巨嘴鸟"},
                { 5314, "巨嘴鸟笼"},
                { 5312, "黄玄凤鹦鹉"},
                { 5315, "黄玄凤鹦鹉笼"},
                { 5313, "灰玄凤鹦鹉"},
                { 5316, "灰玄凤鹦鹉笼"},
                { 5318, "巨嘴鸟雕像"},
                { 5322, "暗影蜡烛"},
                { 5327, "TNT桶"},
                { 5332, "毛绒Spiffo"},
                { 5324, "堆石器（小）"},
                { 5329, "堆石器（中）"},
                { 5330, "堆石器（大）"},
                { 5334, "奥库瑞姆剃刀"},
                { 5335, "和谐传送杖"},
                { 5337, "活力水晶"},
                { 5338, "神盾果"},
                { 5340, "星系珍珠"},
                { 5346, "毒气机关"},
                { 5356, "用过的毒气机关"},
                { 5345, "回声腔"},
                { 5347, "以太天塔柱"},
                { 5355, "炫彩斗篷"},
                { 5353, "以太火把"},
                { 5357, "以太篝火"},
                { 5350, "飞灵"},
                { 5351, "飞灵瓶"},
                { 5358, "贝壳电话（家）"},
                { 5359, "贝壳电话（出生点）"},
                { 5362, "八音盒（以太）"},
                { 5349, "以太块"},
                { 5363, "蜘蛛栖息墙"},
                { 5365, "诅咒蓝砖墙"},
                { 5366, "诅咒蓝板墙"},
                { 5367, "诅咒蓝瓷砖墙"},
                { 5368, "诅咒粉砖墙"},
                { 5369, "诅咒粉板墙"},
                { 5370, "诅咒粉瓷砖墙"},
                { 5371, "诅咒绿砖墙"},
                { 5372, "诅咒绿板墙"},
                { 5373, "诅咒绿瓷砖墙"},
                { 5134, "泰拉改造枪"},
                { 5374, "危险沙岩墙"},
                { 5375, "危险硬化沙墙"},
                { 5376, "禁戒丛林蜥蜴砖墙"},
                { 5378, "诅咒照明弹"},
                { 5382, "华夫饼烘烤模"},
                { 5384, "生命水晶巨石"},
                { 5391, "非负重石"},
                { 5398, "以太砖"},
                { 5397, "以太墙"},
                { 5399, "以太砖墙"},
                { 5386, "Raynebro的连帽衫"},
                { 5390, "Raynebro的兜帽"},
                { 5387, "Raynebro的裤子"},
                { 5392, "黄溶液"},
                { 5393, "白溶液"},
                { 5394, "棕溶液"},
                { 5401, "月锈砖"},
                { 5403, "星芒砖"},
                { 5406, "水星砖"},
                { 5409, "月锈砖墙"},
                { 5411, "星芒砖墙"},
                { 5414, "水星砖墙"},
                { 5400, "最土的块"},
                { 5437, "贝壳电话"},
                { 5451, "四轴竞速无人机"},
                { 5452, "FPV飞行眼镜"},
                { 5453, "小动物友谊指南（停用）"},
                { 5454, "环境保护指南（停用）"},
                { 5455, "和平共处指南（停用）"},
            };
            #endregion

            // 批量插入到数据库
            database.Open();
            var cmd = database.CreateCommand();
            var transaction = database.BeginTransaction();
            cmd.Transaction = transaction;
            try
            {
                foreach (var obj in dict)
                {
                    cmd.CommandText = string.Format("INSERT INTO Wiki (ID, Name) VALUES ({0}, \"{1}\");", obj.Key, obj.Value);
                    cmd.ExecuteNonQuery();
                }
                transaction.Commit();
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                TShock.Log.Error(ex.ToString());
            }
            database.Close();
        }


        /// <summary>
        /// 获得ID
        /// </summary>
        /// <param name="name"></param>
        /// <returns>未找到则返回0</returns>
        public int GetID(string name)
        {
            try
            {
                using QueryResult result = database.QueryReader("SELECT * FROM Wiki WHERE Name = @0;", name);
                if (result.Read())
                {
                    return result.Get<int>("ID");
                }
            }
            catch (Exception ex)
            {
                TShock.Log.Error(ex.ToString());
            }
            return 0;
        }

        /// <summary>
        /// 所有数据
        /// </summary>
        public Dictionary<int, string> All()
        {
            Dictionary<int, string> dict = new();
            try
            {
                using QueryResult result = database.QueryReader("SELECT * FROM Wiki;");
                while (result.Read())
                {
                    dict.Add(result.Get<int>("ID"), result.Get<string>("Name"));
                }
            }
            catch (Exception ex)
            {
                TShock.Log.Error(ex.ToString());
            }
            return dict;
        }

        /// <summary>
        /// 添加/更新 关键词
        /// </summary>
        public void Add(int id, string name)
        {
            if (ContainID(id))
                Update(id, name);
            else
                Insert(id, name);
        }

        bool ContainID(int id)
        {
            try
            {
                using QueryResult result = database.QueryReader("SELECT * FROM Wiki WHERE ID = @0;", id);
                if (result.Read())
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                TShock.Log.Error(ex.ToString());
            }
            return false;
        }

        void Update(int id, string name)
        {
            try
            {
                database.Query("UPDATE Wiki SET Name = @1 WHERE ID = @0;", id, name);
            }
            catch (Exception ex)
            {
                TShock.Log.Error(ex.ToString());
            }
        }

        void Insert(int id, string name)
        {
            try
            {
                database.Query("INSERT INTO Wiki (ID, Name) VALUES (@0, @1);", id, name);
            }
            catch (Exception ex)
            {
                TShock.Log.Error(ex.ToString());
            }
        }

        void Inserts(List<int> ids, string names)
        {

        }
    }
}
